#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
int main()
{
    const char *filename = "./test.txt";
    int fd = open(filename, O_RDONLY | O_CREAT, 0644);
    if (fd == -1)
    {
        perror("open error:");
        exit(-1);
    }

    printf("fd = %d\n", fd);

    /* 绝对路径 */
    const char *filename2 = "des.txt";
    int fd2 = open(filename2, O_WRONLY | O_CREAT, 0777);
    if (fd2 == -1)
    {
        perror("open error:");
        exit(-1);
    }
    printf("fd2 = %d\n", fd2);

    /*关闭文件*/
    close(fd);

    const char *filename3 = "file3.txt";
    int fd3 = open(filename2, O_WRONLY | O_CREAT, 0777);
    if (fd3 == -1)
    {
        perror("open error:");
        exit(-1);
    }
    printf("fd3 = %d\n", fd3);

    return 0;
}